var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var index = require('./routes/index');
var  session  =  require('express-session');
var  app  =  express();

app.use (session({
      secret: 'secret',
        cookie: {
                maxAge: 6000 * 6000 * 6000
        }
}));


// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.engine("html", require("ejs").__express);

app.set('view engine', 'html');

app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));



app.use(function (req, res, next) {
    res.locals.user = req.session.user;
    res.locals.tea = req.session.tea;
    var err1 = req.session.error1;
    var err2 = req.session.error2;
    delete req.session.error1;
    delete req.session.error2;
    res.locals.message1 = "输入用户名";
    res.locals.message2 = "输入密码";
    if (err1) {
        res.locals.message1 = err1;
    } else if (err2) {
        res.locals.message2 = err2;
    }
    next();
});

app.use('/', index);
app.use("/logout", index);
app.use("/admin", index);
app.use("/student", index);
app.use("/teacher", index);
app.use("/class", index);
app.use("/test", index);
app.use("/studentlist", index);
app.use("/download", index);
app.use("/excelup", index);
app.use("/we", index);
app.use("/teacherup", index);
app.use("/teauplist", index);
app.use("/stuup", index);
// app.use("/teauplist2", index);
app.use("/studentup", index);
app.use("/myup", index);
module.exports = app;
